maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=stern
pkgver=1.31.0
pkgrel=0
pkgdesc="Multi pod and container log tailing for Kubernetes"
url="https://github.com/stern/stern"
arch="all"
license="Apache-2.0"
makedepends="go"
checkdepends="tzdata"
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/stern/stern/archive/refs/tags/v$pkgver.tar.gz"
options="net"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	_goldflags="
	-X github.com/stern/stern/cmd.version=$pkgver
	-X github.com/stern/stern/cmd.commit=AlpineLinux
	-X github.com/stern/stern/cmd.date=$(date +%FT%T%Z)
	"
	go build -v -o bin/$pkgname -ldflags "$_goldflags"

	for shell in bash fish zsh; do
		./bin/stern --completion $shell > stern.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 bin/$pkgname -t "$pkgdir"/usr/bin/

	install -Dm644 stern.bash \
		"$pkgdir"/usr/share/bash-completion/completions/stern
	install -Dm644 stern.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_stern
	install -Dm644 stern.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/stern.fish
}

sha512sums="
6bcd1799b32482b7f45ffa389d42e31c509f8b3a307e26d435c037b2418ebb0f478abd4819e05dcf7a9dad8e5b07753f28f074f6e581fd16deda0a5d4978be49  stern-1.31.0.tar.gz
"
